Skip to content

fix: strip proxy env vars from OpenClaw gateway process#13380

Open
SiinXu wants to merge 3 commits intomainfrom
fix/openclaw-gateway-proxy-env
Open

fix: strip proxy env vars from OpenClaw gateway process#13380
SiinXu wants to merge 3 commits intomainfrom
fix/openclaw-gateway-proxy-env

Conversation

@SiinXu
Copy link
Collaborator

@SiinXu SiinXu commented Mar 11, 2026

Summary

  • Strip all proxy-related environment variables (HTTP_PROXY, HTTPS_PROXY, SOCKS_PROXY, etc.) before spawning the OpenClaw gateway process
  • Cherry Studio's ProxyManager sets process.env.HTTP_PROXY which gets inherited by the gateway child process via getShellEnv(). OpenClaw's undici crashes with InvalidArgumentError: Invalid URL protocol when the proxy URL uses a non-http(s) protocol (e.g. socks5://), causing gateway to exit with code 1

Root cause

ProxyManager.setEnvironment(url)     → process.env.HTTP_PROXY = "socks5://127.0.0.1:1080"
getShellEnv() (Windows: copies process.env) → shellEnv includes HTTP_PROXY
crossPlatformSpawn(gateway, { env: shellEnv })  → gateway inherits proxy
undici EnvHttpProxyAgent reads HTTP_PROXY       → InvalidArgumentError → exit code 1

Test plan

  • Set proxy to socks5://127.0.0.1:1080 in Cherry Studio settings → start OpenClaw gateway → should start successfully
  • Set proxy to http://127.0.0.1:7897 → gateway should still work
  • No proxy set → gateway works as before

Closes #13140

🤖 Generated with Claude Code

SiinXu and others added 2 commits March 11, 2026 15:16
Cherry Studio's ProxyManager sets HTTP_PROXY/HTTPS_PROXY on process.env,
which gets inherited by the gateway child process. OpenClaw's undici
crashes with InvalidArgumentError when the proxy URL uses a non-http(s)
protocol (e.g. socks5://), causing gateway to exit with code 1.

Strip all proxy-related env vars before spawning the gateway process.

Closes #13140

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Preserve valid http:// proxy URLs so OpenClaw gateway can still
reach upstream APIs through proxy in restricted networks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@DeJeune
Copy link
Collaborator

DeJeune commented Mar 11, 2026

const loginShellEnvWithoutProxies = Object.fromEntries(
Object.entries(loginShellEnv).filter(([key]) => !key.toLowerCase().endsWith('_proxy'))
) as Record<string, string>

may be reuse it

@kangfenmao kangfenmao requested a review from DeJeune March 12, 2026 02:02
Reuse the same proxy env stripping logic in both OpenClawService and
ClaudeCodeService instead of duplicating it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: if proxy set in cherrystudio, openclaw always start failed: Process exit code 1

2 participants